<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2 class="counter">100</h2>
    <button class="increase">+1</button>
    <button class="decrease">-1</button>

    <script>
        // 获取所有元素
        const counterEl = document.querySelector('.counter')
        const increaseEl = document.querySelector('.increase')
        const decreaseEl = document.querySelector('.decrease')

        // 定义变量

        let counter = 100
        // counterEl.innerHTML = counter

        // 监听按钮的点击
        increaseEl.addEventListener('click', () => {
            counter++
            // 把counter数据重新赋值
            counterEl.innerHTML = counter
        })
        decreaseEl.addEventListener('click', () => {
            counter--
            counterEl.innerHTML = counter
        })
    </script>
</body>

</html>